package com.develop.skwen.basemodule.ui;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;

import com.develop.skwen.basemodule.presenter.BasePresenter;
import com.develop.skwen.basemodule.util.StatusBarUtil;
import com.develop.skwen.basemodule.view.BaseVu;

/**
 * Created by skwen
 * on 18-5-29
 */

public abstract class BaseActivity<P extends BasePresenter,V extends BaseVu> extends AppCompatActivity {

    private P mPresenter;

    private V mVu;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        preBind(savedInstanceState);
        try {
            mVu = getVuClass().newInstance();
            mPresenter = getPresenter();
            mVu.setActivity(this);
            mVu.setPresenter(getPresenter());
            mVu.init(getLayoutInflater(),null);
            setContentView(mVu.getView());
            StatusBarUtil.setTranslucentStatus(this, true);
            onBind();
        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }


    }

    protected abstract Class<? extends V> getVuClass();

    protected abstract P getPresenter();

    protected void preBind(Bundle savedInstanceState) {

    }

    protected abstract void onBind();


    protected V getVu(){
        return mVu;
    }

}
